
#include "SpaceShooter.h"

#include "defs.h"

bool SpaceShooter::init(){

	if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO ) < 0 )
		return false;

	if( TTF_Init() < 0 )
		return false;

	if((dispSurface = SDL_SetVideoMode(WND_WIDTH, WND_HEIGHT, COLOR_DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL)
		return false;

	srand((unsigned int) time(NULL));

	//-----------------------------------------------------

	//background
	if(!spaceBg.init("images/space_1.png"))
		return false;
	spaceBg.setMoving(true);

	//ship
	if(!ship.init("images/ship_1.png", Ship::SHIP_1))
		return false;

	objectList.push_back(&ship);

	if(!enemyShip.init("images/eShip_1.png", Enemy::ESHIP_1))
		return false;
	enemyShip.setPos(370, -120);

	objectList.push_back(&enemyShip);

	// Animation ------------------------------------------

	if(!explosionAnim.init("images/explosion_frames.png", 50, 50, 16))
		return false;

	//-----------------------------------------------------

	//Texts
	if(!initTexts())
		return false;

	SDL_WM_SetCaption("SpaceShooter", NULL);

	//SDL_EnableKeyRepeat(200, 200);
	SDL_ShowCursor(SDL_DISABLE);

	return true;
}

bool SpaceShooter::initTexts(){
	
	if(!healthText.onLoad("fonts/autodestruct.ttf", 16))
		return false;

	healthText.setPos(8, WND_HEIGHT - 24);

	textList.push_back(&healthText);

	return true;
}

